package com.kewo.autioscrollanimviewpagerdemo;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.kewo.autioscrollanimviewpagerdemo.View.AutoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity  {

    private AutoScrollViewPager myViewpager;
    private List<View> mViews;
    private List<Integer> mRes;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mViews=new ArrayList<>();
        mRes=new ArrayList<>();
        mRes.add(R.mipmap.bg1);
        mRes.add(R.mipmap.bg2);
        mRes.add(R.mipmap.bg3);

        for (int i = 0; i < mRes.size(); i++) {
            ImageView imgPic=new ImageView(this);
            imgPic.setImageResource(mRes.get(i));
            imgPic.setScaleType(ImageView.ScaleType.FIT_XY);
            mViews.add(imgPic);
        }
        myViewpager = (AutoScrollViewPager) findViewById(R.id.myViewpager);
//        myViewpager.setOffscreenPageLimit(3);
        myViewpager.setPageMargin(40);
        myViewpager.setAdapter(new MyAdadapter(mViews));
        myViewpager.setPageTransformer(true,new ViewpagerTransformAnim());

        myViewpager.setBorderAnimation(true);
        //设置自动循环轮播，默认开启
        myViewpager.setCycle(true);
//        myViewpager.setSlideBorderMode(AutoScrollViewPager.SLIDE_BORDER_MODE_CYCLE);
        myViewpager.setScrollDurationFactor(10);
        //无效
        //AdViewPager.setDirection(AdViewPager.LEFT);
        //设置循环轮播的事件间隔
        myViewpager.setInterval(3000);
        //设置当触摸模式下的时候停止自动轮播
        // AdViewPager.setStopScrollWhenTouch(true);
        // 开启自动循环轮播
        myViewpager.startAutoScroll();

        myViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {



            }

            @Override
            public void onPageSelected(int position) {


            }

            @Override
            public void onPageScrollStateChanged(int state) {
                switch (state) {

                    case ViewPager.SCROLL_STATE_DRAGGING:
                        //Log.e("====", "===拖动状态===");
                        myViewpager.stopAutoScroll();
                        break;
                    case ViewPager.SCROLL_STATE_IDLE:
                        //Log.e("====", "===空闲状态===");
                        myViewpager.startAutoScroll();
                        break;
                    case ViewPager.SCROLL_STATE_SETTLING:
                        //Log.e("====", "===开始切换===");
                        break;
                }

            }
        });

    }
    class MyPicAdapter extends PagerAdapter{
        List<View> viewList;
        @Override
        public int getCount() {
            return 0;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return false;
        }
    }

}
